package GreedyAlgorithm;

import primaryAlgorithm.Code02;

import java.util.Arrays;

public class Code01 {
    /*分发饼干 https://leetcode-cn.com/leetbook/read/greedy/rvrk1c/*/
    public int findContentChildren(int[] g, int[] s) { // 返回能满足的孩子数量 g代表胃口值 s代表饼干数量和大小  g = [1,2,3], s = [1,1]
        Arrays.sort(g);
        Arrays.sort(s);

        int childNumber = 0;
        // 孩子是必须考虑的
        for (int i = 0; i < s.length; i++) {
            if (s[i] >= g[childNumber]){
                childNumber++;
                if (childNumber > g.length-1)
                    return childNumber;
            }
        }

        return childNumber;
    }

    public static void main(String[] args) {
        Code01 code01 = new Code01();
        System.out.println("code01.findContentChildren(new int[]{1,2,3},new int[]{1,1}) = " + code01.findContentChildren(new int[]{1, 2, 3}, new int[]{1, 1}));
        System.out.println("code01.findContentChildren(new int[]{1,2},new int[]{1,2,3}) = " + code01.findContentChildren(new int[]{1, 2}, new int[]{1, 2, 3}));
    }
}
